import { Body, Inject, Post, Provide } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { TodoEntity } from '../../entity/todo';
import { TodoService } from '../../service/todo';

/**
 * 待办事项管理
 */
@Provide()
@CoolController({
    api: ['add', 'delete', 'update', 'info', 'list', 'page'],
    entity: TodoEntity,
    service: TodoService,
    pageQueryOp: {
        keyWordLikeFields: ['a.name', 'a.description'],
        fieldEq: ['projectId', 'status', 'execUserId'],
        select: ['a.*', 'b.nickName as execUserName', 'b.avatarUrl as execUserAvatar'],
        join: [
            {
                entity: 'user_info',
                alias: 'b',
                condition: 'a.execUserId = b.id',
                type: 'leftJoin'
            }
        ],
        addOrderBy: {
            createTime: 'DESC'
        }
    }
})
export class TodoController extends BaseController {
    @Inject()
    todoService: TodoService;

    /**
     * 增加待办事项时长
     */
    @Post('/addTime')
    async updateTime(@Body() body: any) {
        const { todoId, minutes } = body;
        await this.todoService.addTotalTime(todoId, minutes);
        return this.ok();
    }

    /**
     * 更新待办事项状态
     */
    @Post('/status')
    async status(@Body() body: any) {
        const { id, status } = body;
        await this.todoService.updateStatus(id, status);
        return this.ok();
    }
} 